#include <iostream>
#include <fstream>
#include "tangram.h"
#include "logger.h"

using namespace std;

#ifdef WIN32
#define LOG_FILE "D:\\tangram.log"
#else
#define LOG_FILE "/tmp/tangram.log"
#endif

static ofstream log_file;

Logger::Logger(void)
{
}

Logger::~Logger(void)
{
}

void Logger::Log(LogLevel level, const char *msg, ...)
{
	static char buffer[MAX_LOG_LEN];
	memset(buffer, 0x0, sizeof(buffer));

	va_list ap;
	va_start(ap, msg);
	vsnprintf(buffer, sizeof(buffer), msg, ap);
	va_end(ap);

	cout << buffer << endl;
	log_file << buffer << endl;
}

void Log(LogLevel level, const std::string &msg, ...)
{
	static char buffer[MAX_LOG_LEN];
	memset(buffer, 0x0, sizeof(buffer));

	va_list ap;
	va_start(ap, msg);
	vsnprintf(buffer, sizeof(buffer), msg.c_str(), ap);
	va_end(ap);

	cout << buffer << endl;
	log_file << buffer << endl;
}

